home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13020 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 3 Apr 1996 18:57:42 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4jv6q6$cpn@solutions.solon.com>
  10. References: <4ianbf$h86@solutions.solon.com> <4io1io$no4@solutions.solon.com> <4j41ru$nq4@solutions.solon.com> <4jttlq$3p1@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4jttlq$3p1@solutions.solon.com>,
  14. Niall Smart <nsmart@indigo.ie> wrote:
  15.  >Michael Smith <msmith@mpx.com.au> wrote:
  16.  >
  17.  >>Konrad Schwarz wrote:
  18.  >>> 
  19.  >>> I recently wrote a loop that went like this:
  20.  >>> 
  21.  >>> while (p < end_p)
  22.  >>>         ++*p++;
  23.  >>> 
  24.  >
  25.  >>This is largely a matter of taste
  26.  >
  27.  >I would argue that it is far more than that.
  28.  >
  29.  >>, but personally I don't like that 
  30.  >>construct.  A programmer less skilled than you might easily misunderstand 
  31.  >>that and introduce an error.  I would prefer:
  32.  >
  33.  >>for ( ; p<end_p; p++) 
  34.  >>    ++(*p);
  35.  >
  36.  >or either of:
  37.  >
  38.  >while (p < end_p)
  39.  >{
  40.  >    (*p)++;
  41.  >    p++;
  42.  >}
  43.  >
  44.  >while (p++ < end_p)
  45.  >{
  46.  >    (*p)++;
  47.  >}
  48.  >
  49.  >Zero chance for ambiguity in the last three versions.
  50.  
  51. There is zero chance for ambiguity in any of the four. The evaluation order is
  52. well defined. I think what you mean is that there is less of a chance (though I
  53. would not say zero) that an inexperienced C programmer will find these three
  54. versions ambiguos. 
  55. -- 
  56.